<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>Chapter 6 Chapter 6 | Data visualisation using R, for researchers who don’t use R</title>
  <meta name="description" content="Abstract here." />
  <meta name="generator" content="bookdown 0.22 and GitBook 2.6.7" />

  <meta property="og:title" content="Chapter 6 Chapter 6 | Data visualisation using R, for researchers who don’t use R" />
  <meta property="og:type" content="book" />
  
  
  <meta property="og:description" content="Abstract here." />
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="Chapter 6 Chapter 6 | Data visualisation using R, for researchers who don’t use R" />
  
  <meta name="twitter:description" content="Abstract here." />
  

<meta name="author" content="Emily Nordmann, Phil McAleer, Wilhelmiina Toivo, Helena Paterson, Lisa DeBruine" />


<meta name="date" content="2021-06-17" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="chapter-5.html"/>
<link rel="next" href="additional-resources.html"/>
<script src="libs/header-attrs-2.9/header-attrs.js"></script>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />









<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<meta property="og:title" content="IntroDataViz">
<meta property="og:description" content="Data Visualisation Using R, For Researchers Who Don’t Use R.">
<meta property="og:image" content="https://psyteachr.github.io/images/twitter/psyteachr.png">
<meta property="og:url" content="https://psyteachr.github.io/introdataviz/">
<meta property="twitter:card" content="summary_large_image">

<link rel="shortcut icon" href="https://psyteachr.github.io/images/logo.png">


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
div.csl-bib-body { }
div.csl-entry {
  clear: both;
}
.hanging div.csl-entry {
  margin-left:2em;
  text-indent:-2em;
}
div.csl-left-margin {
  min-width:2em;
  float:left;
}
div.csl-right-inline {
  margin-left:2em;
  padding-left:1em;
}
div.csl-indent {
  margin-left: 2em;
}
</style>

<link rel="stylesheet" href="include/psyteachr.css" type="text/css" />
<link rel="stylesheet" href="include/webex.css" type="text/css" />
<link rel="stylesheet" href="include/style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">IntroDataViz</a></li>
<li><a href="https://zenodo.org/badge/latestdoi/166559207"><img src="https://zenodo.org/badge/166559207.svg" alt="DOI"></a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>Overview</a></li>
<li class="chapter" data-level="1" data-path="introduction.html"><a href="introduction.html"><i class="fa fa-check"></i><b>1</b> Introduction</a>
<ul>
<li class="chapter" data-level="1.1" data-path="introduction.html"><a href="introduction.html#why-r-for-data-visualisation"><i class="fa fa-check"></i><b>1.1</b> Why R for data visualisation?</a></li>
<li class="chapter" data-level="1.2" data-path="introduction.html"><a href="introduction.html#a-layered-grammar-of-graphics"><i class="fa fa-check"></i><b>1.2</b> A layered grammar of graphics</a></li>
<li class="chapter" data-level="1.3" data-path="introduction.html"><a href="introduction.html#simulated-dataset"><i class="fa fa-check"></i><b>1.3</b> Simulated dataset</a></li>
<li class="chapter" data-level="1.4" data-path="introduction.html"><a href="introduction.html#setting-up-r-and-rstudio"><i class="fa fa-check"></i><b>1.4</b> Setting up R and RStudio</a></li>
<li class="chapter" data-level="1.5" data-path="introduction.html"><a href="introduction.html#preparing-your-data"><i class="fa fa-check"></i><b>1.5</b> Preparing your data</a>
<ul>
<li class="chapter" data-level="1.5.1" data-path="introduction.html"><a href="introduction.html#data-format"><i class="fa fa-check"></i><b>1.5.1</b> Data format</a></li>
<li class="chapter" data-level="1.5.2" data-path="introduction.html"><a href="introduction.html#variable-names"><i class="fa fa-check"></i><b>1.5.2</b> Variable names</a></li>
<li class="chapter" data-level="1.5.3" data-path="introduction.html"><a href="introduction.html#data-values"><i class="fa fa-check"></i><b>1.5.3</b> Data values</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="2" data-path="chapter-2.html"><a href="chapter-2.html"><i class="fa fa-check"></i><b>2</b> Chapter 2</a>
<ul>
<li class="chapter" data-level="2.1" data-path="chapter-2.html"><a href="chapter-2.html#loading-packages"><i class="fa fa-check"></i><b>2.1</b> Loading packages</a></li>
<li class="chapter" data-level="2.2" data-path="chapter-2.html"><a href="chapter-2.html#loading-data"><i class="fa fa-check"></i><b>2.2</b> Loading data</a></li>
<li class="chapter" data-level="2.3" data-path="chapter-2.html"><a href="chapter-2.html#handling-numeric-factors"><i class="fa fa-check"></i><b>2.3</b> Handling numeric factors</a></li>
<li class="chapter" data-level="2.4" data-path="chapter-2.html"><a href="chapter-2.html#argument-names"><i class="fa fa-check"></i><b>2.4</b> Argument names</a></li>
<li class="chapter" data-level="2.5" data-path="chapter-2.html"><a href="chapter-2.html#demographic-information"><i class="fa fa-check"></i><b>2.5</b> Demographic information</a></li>
<li class="chapter" data-level="2.6" data-path="chapter-2.html"><a href="chapter-2.html#bar-chart-of-counts"><i class="fa fa-check"></i><b>2.6</b> Bar chart of counts</a></li>
<li class="chapter" data-level="2.7" data-path="chapter-2.html"><a href="chapter-2.html#plotting-existing-aggregates-and-percent"><i class="fa fa-check"></i><b>2.7</b> Plotting existing aggregates and percent</a></li>
<li class="chapter" data-level="2.8" data-path="chapter-2.html"><a href="chapter-2.html#histogram"><i class="fa fa-check"></i><b>2.8</b> Histogram</a></li>
<li class="chapter" data-level="2.9" data-path="chapter-2.html"><a href="chapter-2.html#customisation-1"><i class="fa fa-check"></i><b>2.9</b> Customisation 1</a>
<ul>
<li class="chapter" data-level="2.9.1" data-path="chapter-2.html"><a href="chapter-2.html#changing-colours"><i class="fa fa-check"></i><b>2.9.1</b> Changing colours</a></li>
<li class="chapter" data-level="2.9.2" data-path="chapter-2.html"><a href="chapter-2.html#editing-axis-names-and-labels"><i class="fa fa-check"></i><b>2.9.2</b> Editing axis names and labels</a></li>
<li class="chapter" data-level="2.9.3" data-path="chapter-2.html"><a href="chapter-2.html#discrete-vs.-continuous-errors"><i class="fa fa-check"></i><b>2.9.3</b> Discrete vs. continuous errors</a></li>
<li class="chapter" data-level="2.9.4" data-path="chapter-2.html"><a href="chapter-2.html#adding-a-theme"><i class="fa fa-check"></i><b>2.9.4</b> Adding a theme</a></li>
</ul></li>
<li class="chapter" data-level="2.10" data-path="chapter-2.html"><a href="chapter-2.html#activities-1"><i class="fa fa-check"></i><b>2.10</b> Activities 1</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="chapter-3.html"><a href="chapter-3.html"><i class="fa fa-check"></i><b>3</b> Chapter 3</a>
<ul>
<li class="chapter" data-level="3.1" data-path="chapter-3.html"><a href="chapter-3.html#data-formats"><i class="fa fa-check"></i><b>3.1</b> Data formats</a></li>
<li class="chapter" data-level="3.2" data-path="chapter-3.html"><a href="chapter-3.html#transforming-data"><i class="fa fa-check"></i><b>3.2</b> Transforming data</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="chapter-3.html"><a href="chapter-3.html#step-1-pivot_longer"><i class="fa fa-check"></i><b>3.2.1</b> Step 1: <code>pivot_longer()</code></a></li>
<li class="chapter" data-level="3.2.2" data-path="chapter-3.html"><a href="chapter-3.html#step-2-pivot_longer-adjusted"><i class="fa fa-check"></i><b>3.2.2</b> Step 2: <code>pivot_longer()</code> adjusted</a></li>
<li class="chapter" data-level="3.2.3" data-path="chapter-3.html"><a href="chapter-3.html#step-3-pivot_wider"><i class="fa fa-check"></i><b>3.2.3</b> Step 3: <code>pivot_wider()</code></a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="chapter-3.html"><a href="chapter-3.html#histogram-2"><i class="fa fa-check"></i><b>3.3</b> Histogram 2</a></li>
<li class="chapter" data-level="3.4" data-path="chapter-3.html"><a href="chapter-3.html#density-plots"><i class="fa fa-check"></i><b>3.4</b> Density plots</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="chapter-3.html"><a href="chapter-3.html#grouped-density-plots"><i class="fa fa-check"></i><b>3.4.1</b> Grouped density plots</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="chapter-3.html"><a href="chapter-3.html#scatterplots"><i class="fa fa-check"></i><b>3.5</b> Scatterplots</a>
<ul>
<li class="chapter" data-level="3.5.1" data-path="chapter-3.html"><a href="chapter-3.html#grouped-scatterplots"><i class="fa fa-check"></i><b>3.5.1</b> Grouped scatterplots</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="chapter-3.html"><a href="chapter-3.html#transforming-data-2"><i class="fa fa-check"></i><b>3.6</b> Transforming data 2</a></li>
<li class="chapter" data-level="3.7" data-path="chapter-3.html"><a href="chapter-3.html#customisation-2"><i class="fa fa-check"></i><b>3.7</b> Customisation 2</a>
<ul>
<li class="chapter" data-level="3.7.1" data-path="chapter-3.html"><a href="chapter-3.html#accessible-colour-schemes"><i class="fa fa-check"></i><b>3.7.1</b> Accessible colour schemes</a></li>
</ul></li>
<li class="chapter" data-level="3.8" data-path="chapter-3.html"><a href="chapter-3.html#activities-2"><i class="fa fa-check"></i><b>3.8</b> Activities 2</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="chapter-4.html"><a href="chapter-4.html"><i class="fa fa-check"></i><b>4</b> Chapter 4</a>
<ul>
<li class="chapter" data-level="4.1" data-path="chapter-4.html"><a href="chapter-4.html#boxplots"><i class="fa fa-check"></i><b>4.1</b> Boxplots</a>
<ul>
<li class="chapter" data-level="4.1.1" data-path="chapter-4.html"><a href="chapter-4.html#grouped-boxplots"><i class="fa fa-check"></i><b>4.1.1</b> Grouped boxplots</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="chapter-4.html"><a href="chapter-4.html#violin-plots"><i class="fa fa-check"></i><b>4.2</b> Violin plots</a></li>
<li class="chapter" data-level="4.3" data-path="chapter-4.html"><a href="chapter-4.html#bar-chart-of-means"><i class="fa fa-check"></i><b>4.3</b> Bar chart of means</a></li>
<li class="chapter" data-level="4.4" data-path="chapter-4.html"><a href="chapter-4.html#violin-boxplot"><i class="fa fa-check"></i><b>4.4</b> Violin-boxplot</a>
<ul>
<li class="chapter" data-level="4.4.1" data-path="chapter-4.html"><a href="chapter-4.html#grouped-violin-boxplots"><i class="fa fa-check"></i><b>4.4.1</b> Grouped violin-boxplots</a></li>
</ul></li>
<li class="chapter" data-level="4.5" data-path="chapter-4.html"><a href="chapter-4.html#customisation-part-3"><i class="fa fa-check"></i><b>4.5</b> Customisation part 3</a></li>
<li class="chapter" data-level="4.6" data-path="chapter-4.html"><a href="chapter-4.html#activities-3"><i class="fa fa-check"></i><b>4.6</b> Activities 3</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="chapter-5.html"><a href="chapter-5.html"><i class="fa fa-check"></i><b>5</b> Chapter 5</a>
<ul>
<li class="chapter" data-level="5.1" data-path="chapter-5.html"><a href="chapter-5.html#interaction-plots"><i class="fa fa-check"></i><b>5.1</b> Interaction plots</a></li>
<li class="chapter" data-level="5.2" data-path="chapter-5.html"><a href="chapter-5.html#combined-interaction-plots"><i class="fa fa-check"></i><b>5.2</b> Combined interaction plots</a></li>
<li class="chapter" data-level="5.3" data-path="chapter-5.html"><a href="chapter-5.html#facets"><i class="fa fa-check"></i><b>5.3</b> Facets</a></li>
<li class="chapter" data-level="5.4" data-path="chapter-5.html"><a href="chapter-5.html#saving-plots"><i class="fa fa-check"></i><b>5.4</b> Saving plots</a></li>
<li class="chapter" data-level="5.5" data-path="chapter-5.html"><a href="chapter-5.html#exporting-plots"><i class="fa fa-check"></i><b>5.5</b> Exporting plots</a></li>
<li class="chapter" data-level="5.6" data-path="chapter-5.html"><a href="chapter-5.html#multiple-plots"><i class="fa fa-check"></i><b>5.6</b> Multiple plots</a>
<ul>
<li class="chapter" data-level="5.6.1" data-path="chapter-5.html"><a href="chapter-5.html#combining-two-plots"><i class="fa fa-check"></i><b>5.6.1</b> Combining two plots</a></li>
<li class="chapter" data-level="5.6.2" data-path="chapter-5.html"><a href="chapter-5.html#combining-three-or-more-plots"><i class="fa fa-check"></i><b>5.6.2</b> Combining three or more plots</a></li>
</ul></li>
<li class="chapter" data-level="5.7" data-path="chapter-5.html"><a href="chapter-5.html#customisation-part-4"><i class="fa fa-check"></i><b>5.7</b> Customisation part 4</a>
<ul>
<li class="chapter" data-level="5.7.1" data-path="chapter-5.html"><a href="chapter-5.html#axis-labels"><i class="fa fa-check"></i><b>5.7.1</b> Axis labels</a></li>
<li class="chapter" data-level="5.7.2" data-path="chapter-5.html"><a href="chapter-5.html#non-meaningful-colours"><i class="fa fa-check"></i><b>5.7.2</b> Non-meaningful colours</a></li>
</ul></li>
<li class="chapter" data-level="5.8" data-path="chapter-5.html"><a href="chapter-5.html#activities-4"><i class="fa fa-check"></i><b>5.8</b> Activities 4</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="chapter-6.html"><a href="chapter-6.html"><i class="fa fa-check"></i><b>6</b> Chapter 6</a>
<ul>
<li class="chapter" data-level="6.0.1" data-path="chapter-6.html"><a href="chapter-6.html#split-violin-plots"><i class="fa fa-check"></i><b>6.0.1</b> Split-violin plots</a></li>
<li class="chapter" data-level="6.0.2" data-path="chapter-6.html"><a href="chapter-6.html#raincloud-plots"><i class="fa fa-check"></i><b>6.0.2</b> Raincloud plots</a></li>
<li class="chapter" data-level="6.0.3" data-path="chapter-6.html"><a href="chapter-6.html#ridge-plots"><i class="fa fa-check"></i><b>6.0.3</b> Ridge plots</a></li>
<li class="chapter" data-level="6.0.4" data-path="chapter-6.html"><a href="chapter-6.html#alluvial-plots"><i class="fa fa-check"></i><b>6.0.4</b> Alluvial plots</a></li>
</ul></li>
<li class="appendix"><span><b>Appendices</b></span></li>
<li class="chapter" data-level="A" data-path="additional-resources.html"><a href="additional-resources.html"><i class="fa fa-check"></i><b>A</b> Additional resources</a></li>
<li class="chapter" data-level="B" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html"><i class="fa fa-check"></i><b>B</b> Additional advanced plots and customisation options</a>
<ul>
<li class="chapter" data-level="B.1" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#adding-lines-to-plots"><i class="fa fa-check"></i><b>B.1</b> Adding lines to plots</a></li>
<li class="chapter" data-level="B.2" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#zooming-in-and-out"><i class="fa fa-check"></i><b>B.2</b> Zooming in and out</a></li>
<li class="chapter" data-level="B.3" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#setting-the-axis-values"><i class="fa fa-check"></i><b>B.3</b> Setting the axis values</a></li>
<li class="chapter" data-level="B.4" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#controlling-the-legend"><i class="fa fa-check"></i><b>B.4</b> Controlling the Legend</a></li>
<li class="chapter" data-level="B.5" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#setting-a-lab-theme-using-theme"><i class="fa fa-check"></i><b>B.5</b> Setting A Lab Theme using <code>theme()</code></a></li>
<li class="chapter" data-level="B.6" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#easter-egg---overlaying-plots"><i class="fa fa-check"></i><b>B.6</b> Easter Egg - Overlaying Plots</a></li>
<li class="chapter" data-level="B.7" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#easter-egg---a-dumbbell-plot"><i class="fa fa-check"></i><b>B.7</b> Easter Egg - A Dumbbell Plot</a></li>
<li class="chapter" data-level="B.8" data-path="additional-advanced-plots-and-customisation-options.html"><a href="additional-advanced-plots-and-customisation-options.html#easter-egg---a-pie-chart"><i class="fa fa-check"></i><b>B.8</b> Easter Egg - A Pie Chart</a></li>
</ul></li>
<li class="divider"></li>
<li><a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/" 
    target="blank"><img alt="Creative Commons License" 
    style="border-width:0" 
    src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a></li>
<li><a href="https://psyteachr.github.io/books" target="blank">PsyTeachR Books</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Data visualisation using R, for researchers who don’t use R</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="chapter-6" class="section level1" number="6">
<h1><span class="header-section-number">Chapter 6</span> Chapter 6</h1>
<p>This tutorial has but scratched the surface of the visualisation options available using R - in the additional online resources we provide some further advanced plots and customisation options for those readers who are feeling confident with the content covered in this tutorial, however, the below plots give an idea of what is possible, and represent the favourite plots of the authorship team.</p>
<div id="split-violin-plots" class="section level3" number="6.0.1">
<h3><span class="header-section-number">6.0.1</span> Split-violin plots</h3>
<p>Split-violin plots remove the redundancy of mirrored violin plots and make it easier to compare the distributions between multiple conditions.</p>
<div class="sourceCode" id="cb76"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb76-1"><a href="chapter-6.html#cb76-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(dat_long, <span class="fu">aes</span>(<span class="at">x =</span> condition, <span class="at">y =</span> rt, <span class="at">fill =</span> language)) <span class="sc">+</span></span>
<span id="cb76-2"><a href="chapter-6.html#cb76-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_split_violin</span>(<span class="at">alpha =</span> .<span class="dv">4</span>) <span class="sc">+</span></span>
<span id="cb76-3"><a href="chapter-6.html#cb76-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_boxplot</span>(<span class="at">width =</span> .<span class="dv">2</span>, <span class="at">alpha =</span> .<span class="dv">6</span>, <span class="at">show.legend =</span> F) <span class="sc">+</span></span>
<span id="cb76-4"><a href="chapter-6.html#cb76-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">stat_summary</span>(<span class="at">fun.data =</span> <span class="st">&quot;mean_se&quot;</span>, <span class="at">geom =</span> <span class="st">&quot;pointrange&quot;</span>, <span class="at">position =</span> <span class="fu">position_dodge</span>(.<span class="dv">175</span>), <span class="at">show.legend =</span> F)<span class="sc">+</span></span>
<span id="cb76-5"><a href="chapter-6.html#cb76-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_viridis_d</span>(<span class="at">option  =</span><span class="st">&quot;E&quot;</span>) <span class="sc">+</span></span>
<span id="cb76-6"><a href="chapter-6.html#cb76-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb76-7"><a href="chapter-6.html#cb76-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(<span class="at">x =</span> <span class="st">&quot;Condition&quot;</span>, <span class="at">y =</span> <span class="st">&quot;Reaction time (ms)&quot;</span>, <span class="at">fill =</span> <span class="st">&quot;Language group&quot;</span>)</span></code></pre></div>
<div class="figure" style="text-align: center"><span id="fig:unnamed-chunk-2"></span>
<img src="06-ch6_files/figure-html/unnamed-chunk-2-1.png" alt="Split-violin plot" width="100%" />
<p class="caption">
Figure 5.2: Split-violin plot
</p>
</div>
</div>
<div id="raincloud-plots" class="section level3" number="6.0.2">
<h3><span class="header-section-number">6.0.2</span> Raincloud plots</h3>
<p>LISA CAN YOU MAKE MY RAINCLOUD PLOTS LOOKS A BIT BETTER, I CAN’T FIGURE OUT HOW TO JITTER THE RAIN</p>
<p>Raincloud plots combine a density plot, boxplot, raw data points, and any desired summary statistics for a complete visualisation of the data. They are so called because the density plot + raw data is reminiscent of a rain cloud.</p>
<div class="sourceCode" id="cb77"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb77-1"><a href="chapter-6.html#cb77-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(dat_long, <span class="fu">aes</span>(<span class="at">x =</span> condition, <span class="at">y =</span> rt, <span class="at">fill =</span> language))<span class="sc">+</span></span>
<span id="cb77-2"><a href="chapter-6.html#cb77-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_flat_violin</span>(<span class="at">position =</span> <span class="fu">position_nudge</span>(<span class="at">x =</span> .<span class="dv">25</span>, <span class="at">y =</span> <span class="dv">0</span>), </span>
<span id="cb77-3"><a href="chapter-6.html#cb77-3" aria-hidden="true" tabindex="-1"></a>                   <span class="at">trim=</span><span class="cn">FALSE</span>, <span class="at">alpha =</span> <span class="fl">0.6</span>) <span class="sc">+</span></span>
<span id="cb77-4"><a href="chapter-6.html#cb77-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_jitter</span>(<span class="fu">aes</span>(<span class="at">colour =</span> language), <span class="at">size =</span> <span class="dv">2</span>, <span class="at">alpha =</span> .<span class="dv">5</span>, <span class="at">show.legend =</span> <span class="cn">FALSE</span>, <span class="at">position =</span> <span class="fu">position_nudge</span>(<span class="at">x =</span> <span class="sc">-</span>.<span class="dv">25</span>))<span class="sc">+</span></span>
<span id="cb77-5"><a href="chapter-6.html#cb77-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_boxplot</span>(<span class="at">width =</span> .<span class="dv">3</span>, <span class="at">alpha =</span> <span class="fl">0.5</span>, <span class="at">show.legend =</span> F)<span class="sc">+</span></span>
<span id="cb77-6"><a href="chapter-6.html#cb77-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">stat_summary</span>(<span class="at">fun.data =</span> <span class="st">&quot;mean_se&quot;</span>, <span class="at">geom =</span> <span class="st">&quot;pointrange&quot;</span>, <span class="at">position =</span> <span class="fu">position_dodge</span>(.<span class="dv">3</span>), <span class="at">show.legend =</span> F)<span class="sc">+</span></span>
<span id="cb77-7"><a href="chapter-6.html#cb77-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_viridis_d</span>() <span class="sc">+</span></span>
<span id="cb77-8"><a href="chapter-6.html#cb77-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_colour_viridis_d</span>() <span class="sc">+</span></span>
<span id="cb77-9"><a href="chapter-6.html#cb77-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>()<span class="sc">+</span></span>
<span id="cb77-10"><a href="chapter-6.html#cb77-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(<span class="at">x =</span> <span class="st">&quot;Condition&quot;</span>, <span class="at">y =</span> <span class="st">&quot;Reaction time (ms)&quot;</span>, <span class="at">fill =</span> <span class="st">&quot;Language group&quot;</span>) <span class="sc">+</span></span>
<span id="cb77-11"><a href="chapter-6.html#cb77-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">coord_flip</span>()</span></code></pre></div>
<div class="figure" style="text-align: center"><span id="fig:unnamed-chunk-3"></span>
<img src="06-ch6_files/figure-html/unnamed-chunk-3-1.png" alt="Raincloud plot" width="100%" />
<p class="caption">
Figure 5.3: Raincloud plot
</p>
</div>
</div>
<div id="ridge-plots" class="section level3" number="6.0.3">
<h3><span class="header-section-number">6.0.3</span> Ridge plots</h3>
<p>Ridge plots are a series of density plots and show the distribution of numeric values for several groups. Figure X is by <span class="citation">(<a href="#ref-Nation2017" role="doc-biblioref">Nation 2017</a>)</span> and demonstrates how effective this type of visualisation can be to convey a lot of information very intuitively whilst being visually attractive.</p>
<p>LISA I DON’T KNOW HOW TO GIVE THIS A CAPTION AND A FIGURE NUMBER BECAUSE IT’S NOT IN A CODE CHUNK. HAVE I EVER TOLD YOU YOU’RE VERY GOOD AT R</p>
<p><img src="https://raw.githubusercontent.com/zonination/perceptions/master/joy1.png" /></p>
</div>
<div id="alluvial-plots" class="section level3" number="6.0.4">
<h3><span class="header-section-number">6.0.4</span> Alluvial plots</h3>
<p>Alluvial plots visualise multi-level categorical data through flows that can easily be traced in the diagram.</p>
<p>In this tutorial we aimed to provide a practical introduction to common data visualisation techniques using R. Whilst a number of the plots produced in this tutorial can be created in point-and-click software, the underlying skill-set developed by making these visualisations is as powerful as it is extendable.
We hope that this tutorial serves as a jumping off point to encourage more researchers to adopt reproducible workflows and open-access software, in addition to beautiful data visualisations.</p>

</div>
</div>



</div>
<h3>References</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-Nation2017" class="csl-entry">
Nation, Z. 2017. <span>“Perceptions.”</span> <em>GitHub Repository</em>. <a href="https://github.com/zonination/perceptions  ">https://github.com/zonination/perceptions  </a>; GitHub.
</div>
</div>
<div class="psyteachr_footer">
  
</div>
<script>

/* update total correct if #webex-total_correct exists */
update_total_correct = function() {
  if (t = document.getElementById("webex-total_correct")) {
    t.innerHTML =
      document.getElementsByClassName("webex-correct").length + " of " +
      document.getElementsByClassName("webex-solveme").length + " correct";
  }
}

/* webex-solution button toggling function */
b_func = function() {
  var cl = this.parentElement.classList;
  if (cl.contains('open')) {
    cl.remove("open");
  } else {
    cl.add("open");
  }
}

/* function for checking solveme answers */
solveme_func = function(e) {
  var real_answers = JSON.parse(this.dataset.answer);
  var my_answer = this.value;
  var cl = this.classList;
  if (cl.contains("ignorecase")) {
    my_answer = my_answer.toLowerCase();
  }
  if (cl.contains("nospaces")) {
    my_answer = my_answer.replace(/ /g, "")
  }
  
  if (my_answer !== "" & real_answers.includes(my_answer)) {
    cl.add("webex-correct");
  } else {
    cl.remove("webex-correct");
  }

  // match numeric answers within a specified tolerance
  if(this.dataset.tol > 0){
    var tol = JSON.parse(this.dataset.tol);  
    var matches = real_answers.map(x => Math.abs(x - my_answer) < tol)
    if (matches.reduce((a, b) => a + b, 0) > 0) {
      cl.add("webex-correct");
    } else {
      cl.remove("webex-correct");
    }  
  }

  // added regex bit
  if (cl.contains("regex")){
    answer_regex = RegExp(real_answers.join("|"))
    if (answer_regex.test(my_answer)) {
      cl.add("webex-correct");
    }  
  }
  
  update_total_correct();
}

window.onload = function() {
  /* set up solution buttons */
  var buttons = document.getElementsByTagName("button");

  for (var i = 0; i < buttons.length; i++) {
    if (buttons[i].parentElement.classList.contains('webex-solution')) {
      buttons[i].onclick = b_func;
    }
  }
  
  /* set up webex-solveme inputs */
  var solveme = document.getElementsByClassName("webex-solveme");

  for (var i = 0; i < solveme.length; i++) {
    /* make sure input boxes don't auto-anything */
    solveme[i].setAttribute("autocomplete","off");
    solveme[i].setAttribute("autocorrect", "off");
    solveme[i].setAttribute("autocapitalize", "off"); 
    solveme[i].setAttribute("spellcheck", "false");
    solveme[i].value = "";
    
    /* adjust answer for ignorecase or nospaces */
    var cl = solveme[i].classList;
    var real_answer = solveme[i].dataset.answer;
    if (cl.contains("ignorecase")) {
      real_answer = real_answer.toLowerCase();
    }
    if (cl.contains("nospaces")) {
      real_answer = real_answer.replace(/ /g, "");
    }
    solveme[i].dataset.answer = real_answer;
    
    /* attach checking function */
    solveme[i].onkeyup = solveme_func;
    solveme[i].onchange = solveme_func;
  }
  
  update_total_correct();
}

</script>
            </section>

          </div>
        </div>
      </div>
<a href="chapter-5.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="additional-resources.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "google", "twitter", "linkedin", "weibo", "instapaper"],
"google": false
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": {},
"toc": {
"collapse": "section",
"scroll_highlight": true
}
});
});
</script>

</body>

</html>
